import wsgiref.handlers
from google.appengine.ext import webapp

import EventRecord

class UpdateEvent( webapp.RequestHandler ):

  def post( self ):
    self.response.headers['Content-Type'] = 'text/html'

    id = self.request.get('id')
    passcode = self.request.get('passcode')
    title = self.request.get('title')
    date = self.request.get('date')
    time = self.request.get('time')
    venue = self.request.get('venue')

    if not title or not date or not time or not venue:
      self.response.out.write('Fill in all the details to update event.')
      return

    record = EventRecord.EventRecord \
      .gql( 'WHERE id = :1 AND passcode = :2', id, passcode ) \
      .get()
    if not record:
      self.response.out.write( 'Event not found!' )
      return
    record.title = title
    record.date = date
    record.time = time
    record.venue = venue

    record.put()

    self.redirect( 'admin?id=%s&passcode=%s' % (id, passcode) )
  # end of UpdateEvent.post

# end of class UpdateEvent
